<script setup lang="ts">
import {markRaw, onMounted, ref} from "vue";
import type {EChartsOption, EChartsType} from "echarts";
import * as echarts from "echarts";
import {useGetLineDataApi} from "@/api";
import 'echarts-wordcloud'
import type {Line} from "@/interface";

const line = ref()
const option = ref<EChartsOption>()
const myChart = ref<EChartsType>()
const lineData = ref<Line>({
  name: [],
  value:[]
})
const init = async () => {
  const {data: res} = await useGetLineDataApi()
  lineData.value = res
  myChart.value = markRaw(echarts.init(line.value));
  draw();
}
const draw = () => {
  option.value = {
// Make gradient line here
    visualMap: [
      {
        show: false,
        type: 'continuous',
        seriesIndex: 0,
      },
      {
        show: false,
        type: 'continuous',
        seriesIndex: 1,
        dimension: 0,
        min: 0,
        max: lineData.value.value.length - 1
      }
    ],
    title: [
      {
        left: 'center',
        text: '各个月份发布的招聘总数折线图',
        textStyle:{
          color:'#000000'
        }
      }
    ],
    tooltip: {
      trigger: 'axis'
    },
    xAxis: {
      data: lineData.value.name,
      axisLabel:{
        rotate:90,
        color:'#ffffff'
      },
      axisLine:{
        lineStyle:{
          color:'#ffffff'
        }
      }
    },
    yAxis: {
      axisLabel:{
        color:'#ffffff'
      }
    },
    series: [
      {
        name:'职位总数',
        type: 'line',
        showSymbol: false,
        data: lineData.value.value
      }
    ]
  }
  myChart.value.setOption(option.value, {notMerge: true});
}
onMounted(() => {
  init()
})
</script>

<template>
  <div ref="line" class="line">
  </div>
</template>

<style scoped>
.line {
  width: 100%;
  height: 100%;
}
</style>